package com.iwhalecloud.bss.kite.cucc.service.job.scene;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.order.IOrderService;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryGrpMemberDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosDTO;
import com.ztesoft.bss.common.util.SpringUtil;
import com.ztesoft.common.logger.api.ZLogger;
import com.ztesoft.common.logger.factory.ZLoggerFactory;

public class GetMemberUserInfoTask implements Callable<Map<String,Object>> {

    private static final ZLogger LOGGER = ZLoggerFactory.getLogger(GetMemberUserInfoTask.class, KeyConsts.LOG_MODULE);

    private String provinceId;

    private String lanId;

    private String staffCode;

    private QryGrpMemberDTO qryGrpMemberDTO;

    public GetMemberUserInfoTask(String provinceId, String lanId, String staffCode, QryGrpMemberDTO qryGrpMemberDTO) {
        this.provinceId = provinceId;
        this.lanId = lanId;
        this.staffCode = staffCode;
        this.qryGrpMemberDTO = qryGrpMemberDTO;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Map<String,Object> call() throws Exception {
        long time1 = System.currentTimeMillis();

        IOrderService orderService = SpringUtil.getBean(IOrderService.class);

        Map<String, Object> memOrderInfo = orderService
            .getChangeOriginOrder(qryGrpMemberDTO.getMemGoodsId(), qryGrpMemberDTO.getMemCustId(),
                qryGrpMemberDTO.getMemSerialNumber(), this.provinceId, this.lanId, this.staffCode, qryGrpMemberDTO.getMemUserId());
        KitePosDTO memKitePosDTO = JSONObject
            .toJavaObject(JSON.parseObject(JSON.toJSONString(memOrderInfo)), KitePosDTO.class);
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("orderId", KiteMapUtils.getString((Map<String, ?>) memOrderInfo.get("order"), "orderId"));
        result.put("serialNumber", qryGrpMemberDTO.getMemSerialNumber());
        result.put("memKitePosDTO", memKitePosDTO);

        long time2 = System.currentTimeMillis();
        LOGGER.info("getChangeOriginOrder ============ "+qryGrpMemberDTO.getMemSerialNumber()+" : "+ (time2 - time1));

        return result;
    }

}
